from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.db.database import get_db
from app.models.dict_model import Dict

router = APIRouter(prefix="", tags=["字典"])

@router.get("/{group_code}")
def get_dict(group_code: str, db: Session = Depends(get_db)):
    rows = db.query(Dict).filter(Dict.group_code == group_code).all()
    # 转字典并去掉 SQLAlchemy 内部字段
    return {
        "code":200,
        "message":"sucess",
        "data":[
        {
            "id": r.id,
            "group_code": r.group_code,
            "item_code": r.item_code,
            "item_name": r.item_name,
        }
        for r in rows
    ]
}